package com.hrms.hrms_security.component;

import com.hrms.hrms_security.utils.MD5Utils;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * password加密解密处理类
 */

@NoArgsConstructor
@Component
public class PasswordEncoder2 extends BCryptPasswordEncoder {

    @Value("${zcblog.rsa.PRIVATE_KEY}")
    private static String PRIVATE_KEY;

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        // 接收到的前端的密码
        String pwd = rawPassword.toString();
//        pwd = RSAUtils.decryptByPrivate(pwd, RsaProperties.privateKey);

        if (encodedPassword != null && encodedPassword.length() != 0) {
            return MD5Utils.passwordIsTrue(pwd, encodedPassword);
        } else {
            return false;
        }
    }

    @Override
    public String encode(CharSequence rawPassword) {
        return MD5Utils.string2MD5((String) rawPassword);
    }
}

